package com.ruoyi.web.controller.installation;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterMeterrepairinfo;
import com.ruoyi.system.service.IWaterMeterrepairinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 表具维修Controller
 *
 * @author ruoyi
 * @date 2025-09-17
 */
@RestController
@RequestMapping("/installation/repairInfo")
public class WaterMeterrepairinfoController extends BaseController
{
    @Autowired
    private IWaterMeterrepairinfoService waterMeterrepairinfoService;

    /**
     * 查询表具维修列表
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterMeterrepairinfo waterMeterrepairinfo)
    {
        startPage();
        List<WaterMeterrepairinfo> list = waterMeterrepairinfoService.selectWaterMeterrepairinfoList(waterMeterrepairinfo);
        return getDataTable(list);
    }

    /**
     * 导出表具维修列表
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:export')")
    @Log(title = "表具维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterMeterrepairinfo waterMeterrepairinfo)
    {
        List<WaterMeterrepairinfo> list = waterMeterrepairinfoService.selectWaterMeterrepairinfoList(waterMeterrepairinfo);
        ExcelUtil<WaterMeterrepairinfo> util = new ExcelUtil<WaterMeterrepairinfo>(WaterMeterrepairinfo.class);
        util.exportExcel(response, list, "表具维修数据");
    }

    /**
     * 获取表具维修详细信息
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterMeterrepairinfoService.selectWaterMeterrepairinfoById(id));
    }

    /**
     * 新增表具维修
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:add')")
    @Log(title = "表具维修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterMeterrepairinfo waterMeterrepairinfo)
    {
        LoginUser loginUser = getLoginUser();
        waterMeterrepairinfo.setCompanyId(loginUser.getDeptId().toString());
        waterMeterrepairinfo.setRepairState("0");

        int resultNum = waterMeterrepairinfoService.insertWaterMeterrepairinfo(waterMeterrepairinfo);
        if(resultNum>0){
            return toAjax(resultNum);
        }
        return AjaxResult.warn("该工单已经创建过维修记录");
    }

    /**
     * 修改表具维修
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:edit')")
    @Log(title = "表具维修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterMeterrepairinfo waterMeterrepairinfo)
    {
        return toAjax(waterMeterrepairinfoService.updateWaterMeterrepairinfo(waterMeterrepairinfo));
    }

    /**
     * 删除表具维修
     */
    @PreAuthorize("@ss.hasPermi('installation:repairInfo:remove')")
    @Log(title = "表具维修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterMeterrepairinfoService.deleteWaterMeterrepairinfoByIds(ids));
    }
}
